
const R = require('ramda');
const fs = require('fs');
const path = require('path');


const map = R.curry(function (f,any_functor) {
    return any_functor.map(f);
});



let counter = 1;
class IO{
    constructor(f){
        // console.log(`counter:`,counter++);
        this.unsafefunc = f;
    }

    map(f){
        return IO.of(R.compose(f,this.unsafefunc));
    }

    join(){
       return this.unsafefunc();
    }

    static of(f){
        return new IO(f);
    }
}


const readFile = function (filename) {
  return new IO(function () {
      return fs.readFileSync(filename,'utf8');
  })
};

const print = function (x) {
    return new IO(function () {
        console.log(x);
        return x;
    })
};


const log = function(x){
    return new IO(function () {
        console.log(x);
        return x;
    })
};

// let cat = R.compose(map(print),readFile);


function test_throw() {
    throw new Error("this is throw!");
}

